package com.xiaoyang.system.controller.exam;

import com.xiaoyang.common.core.controller.BaseController;
import com.xiaoyang.common.core.domain.R;
import com.xiaoyang.common.core.domain.TableDataInfo;
import com.xiaoyang.system.domain.exam.dto.ExamAddDTO;
import com.xiaoyang.system.domain.exam.dto.ExamEditDTO;
import com.xiaoyang.system.domain.exam.dto.ExamQueryAddDTO;
import com.xiaoyang.system.domain.exam.dto.ExamQueryDTO;
import com.xiaoyang.system.domain.exam.vo.ExamDetailVO;
import com.xiaoyang.system.service.exam.IExamService;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/exam")
@Tag(name = "竞赛管理接口")
public class ExamController extends BaseController {

    @Autowired
    private IExamService examService;

    /**
     * 竞赛列表
     * @param examQueryDTO
     * @return
     */
    @GetMapping("/list")
    public TableDataInfo list(ExamQueryDTO examQueryDTO) {
        return getDataTable(examService.list(examQueryDTO));
    }

    /**
     * 添加竞赛
     * @param examAddDTO
     * @return
     */
    @PostMapping("/add")
    public R<String> add(@RequestBody ExamAddDTO examAddDTO) {
        return R.ok(examService.add(examAddDTO));
    }

    /**
     * 添加竞赛题目
     * @param examQueryAddDTO
     * @return
     */
    @PostMapping("/question/add")
    public R<Void> questionAdd(@RequestBody ExamQueryAddDTO examQueryAddDTO) {
        return toR(examService.questionAdd(examQueryAddDTO));
    }

    /**
     * 删除竞赛题目
     * @param examId        竞赛id
     * @param questionId    题目id
     * @return
     */
    @DeleteMapping("/question/delete")
    public R<Void> questionDelete(Long examId, Long questionId) {
        return toR(examService.questionDelete(examId, questionId));
    }

    /**
     * 查询竞赛详情
     * @param examId
     * @return
     */
    @GetMapping("/detail")
    public R<ExamDetailVO> detail(Long examId) {
        return R.ok(examService.detail(examId));
    }

    /**
     * 编辑竞赛信息
     * @param examEditDTO
     * @return
     */
    @PutMapping("/edit")
    public R<Void> edit(@RequestBody ExamEditDTO examEditDTO) {
        return toR(examService.edit(examEditDTO));
    }

    /**
     * 删除竞赛
     * @param examId
     * @return
     */
    @DeleteMapping("/delete")
    public R<Void> delete(Long examId) {
        return toR(examService.delete(examId));
    }

    /**
     * 发布竞赛
     * @param examId 竞赛id
     * @return
     */
    @PutMapping("publish")
    public R<Void> publish(Long examId) {
        return toR(examService.publish(examId));
    }

    /**
     * 取消发布竞赛
     * @param examId 竞赛id
     * @return
     */
    @PutMapping("cancelPublish")
    public R<Void> cancelPublish(Long examId) {
        return toR(examService.cancelPublish(examId));
    }
}
